#include "globals.h"
/**
TODO:Description.
@param sub_mask supplies the pointer to the subnet mask that would be
                calculated.
*/
void
get_subnet_mask(
    char ip_addr[],
    char net_msk[],
    char sub_msk[]
    )
{
    int p1; 
    int p2;
    int j;

    //
    // The for loop below finds the subnet mask for each interface 
    // using the IP address and the network mask
    //

    for( p1 = 0, p2 = 0, j = 0; j < 4; j++, p1++, p2++ ) 
    {
        int a;
        int b; 
        int k;
        
        char s1[4] = "\0";
        char s2[4] = "\0";
        
        for( k = 0; ip_addr[p1] != '.' && k < 4; k++ )
        {
            s1[k] = ip_addr[p1++];
        }	
        
        for( k = 0; net_msk[p2] != '.' && k < 4; k++ )
        {
            s2[k] = net_msk[p2++];
        }

        a=atoi(s1);
        b=atoi(s2);	
        sprintf(s1,"%d%s",a&b,"\0");

        if(j)
        {
            strcat( sub_msk, "." );	
        }
        
        strcat( sub_msk, s1 );			
    }
}

